import React from 'react'
import { Card } from 'antd'
import { Link } from 'react-router-dom'
import { store } from '../../store/store'

class PCNewsBlock extends React.Component {
  constructor(props) {
    super(props);
    this.state = {
      news: ''
    }
  }

  componentDidMount() {
    const type = this.props.type
    const count = this.props.count
    store.getNews(type, count)
      .then(news => {
        this.setState({
          news
        })
      })
  }

  render() {
    const { news } = this.state
    const newsList = news.length
      ? (
        news.map((newsItem, index) => {
          return (
            <li key={index}>
              <Link to={`/detail/${newsItem.uniquekey}`}>
                {newsItem.title}
              </Link>
            </li>
          )
        })
      )
      : (
        <span>没有加载任何消息</span>
      );
    return (
      <Card>
        <ul className='pc__container__topNewsList'>
          {newsList}
        </ul>
      </Card>
    )
  }
}

export default PCNewsBlock